package com.example.newsapp.ui.screens.mainScreens

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.newsapp.data.compositionLocal.LocalNavController
import com.example.newsapp.data.list.pageList
import com.example.newsapp.ui.components.mainComponent.BottomNavigationBar
import com.example.newsapp.ui.components.mainComponent.DrawerNavigationBar

// 总界面
@Composable
fun MainFrame(modifier: Modifier = Modifier) {
    // 开启协程
    val scope = rememberCoroutineScope()
    // 导航控制器
    var navController = rememberNavController()
    // 获取堆栈导航当前页
    var currentDestination = navController.currentBackStackEntryAsState().value?.destination

    // 脚手架
    Scaffold(
        bottomBar = {
            AnimatedVisibility(currentDestination?.route in pageList) {
                BottomNavigationBar(
                    navController = navController
                )
            }
        }
    ) {
        CompositionLocalProvider(
            LocalNavController provides navController
        ) {
            // 侧边抽屉式导航栏及导航图
            DrawerNavigationBar(it, scope)
        }
    }
}